< previous page page_142 next page >

Page 142
If you choose to display an icon in the message box, you have a choice of four icons. These icons and their purposes are summarized in Table 7.1.
Table 7.1 Icons Indicate the Type of Message Being Shown
Icon NameTypical Purpose
Critical MessageIndicates that a severe error has occurred. Often a program is shut down after this message.
Warning MessageIndicates that a program error has occurred; this error may require user correction or may lead to undesirable results.
QueryIndicates that the program requires additional information from the user before processing can continue.
Information MessageInforms the user of the status of the program. This message is often used to notify the users of the completion of a task.

To tell Visual Basic that you want to use a particular icon in the message box, you set a value for the buttons argument of the MsgBox function. The buttons argument can be set to one of four values, as defined in the following table. You can use either the numerical value or the constant from the following table:
Message TypeArgument ValueConstant
Critical16vbCritical
Query32vbQuestion
Warning48vbExclamation
Information64vbInformation

tip.gif
Good programming practice dictates that you use the appropriate constant to represent the integer value. Using the correct constant makes your programs more readable and will not require any conversion should Microsoft change the arguments' values.

note.gif The constants listed in the preceding table not only affect the icon that is displayed, but also the sound produced by Windows when a message appears. You can set sounds for different message types in the Windows Control Panel. square.gif

To illustrate how icons and titles can be used in your message boxes, enter the following code, which produces the message box shown in Figure 7.2:
MsgBox "This message box contains an icon.", vbInformation, "Icon Demo"

 
< previous page page_142 next page >